package com.douyang.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.douyang.base.model.Result;
import com.douyang.dto.ChangStockDTO;
import com.douyang.dto.SeckKillDTO;
import com.douyang.model.SeckKill;
import com.douyang.service.SeckKillService;
import com.douyang.vo.SeckKillVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoma
 * @since 2025-03-19
 */
@RestController
@RequestMapping("/trade/seckKill")
public class SeckKillController {

    @Autowired
    SeckKillService seckKillService;

    @GetMapping("/getSeckKillList")
    public Result<List<SeckKillVO>> getSeckKillList() {
        return Result.success(seckKillService.getSeckKillList());
    }

    @PostMapping("/tryToSeckKill/{killId}")
    public Result<String> tryToSeckKill(@PathVariable("killId") Long killId) {
        seckKillService.tryToSeckKill(killId);
        return Result.success("ok");
    }

    @PostMapping("/addSeckKill")
    @SaCheckRole("admin")
    public Result<String> addSeckKill(@RequestBody @Validated SeckKillDTO seckKillDTO) {

        seckKillService.addSeckKill(seckKillDTO);
        return Result.success("ok");
    }

    @DeleteMapping("/deleteSeckKill/{id}")
    @SaCheckRole("admin")
    public Result<String> deleteSeckKill(@PathVariable("id") Long id) {
        seckKillService.deleteSeckKill(id);
        return Result.success("ok");
    }

    @PutMapping("/changStock")
    @SaCheckRole("admin")
    public Result<String> changStock(@RequestBody @Validated ChangStockDTO changStockDTO) {
        seckKillService.changStock(changStockDTO);
        return Result.success("ok");
    }


}
